<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:if test="${userID==null}">
    <c:redirect url="index-msa.jsp" />
</c:if>
<c:if test="${param.mode=='del'}">
    <sql:update dataSource="${dataSource}">
        delete from t_messages where c_forum_code = ? and c_number = ? 
        <sql:param value="${param.forum}" />
        
        <sql:param value="${param.msgnum}" />
    </sql:update>
    
    <c:url value="${pageContext.request.requestURI}" var="rtn">
        <c:param name="id" value="${param.forum}" />
    </c:url>
    
    <c:redirect url="${rtn}" /> 
</c:if>

<sql:query var="forums" dataSource="${dataSource}">
    select c_code,c_name from t_forums where c_code=? 
    <sql:param value="${param.id}" />
</sql:query>

<c:forEach var="row" items="${forums.rows}">
    <c:set var="name" value="${row.c_name}" />
</c:forEach>

<html>
    <head>
        <title><c:out value="${name}"/></title>
    </head>
    
    <body>
        <sql:query var="messages" dataSource="${dataSource}">
            select * from t_messages where c_forum_code = ? order by c_number 
            <sql:param value="${param.id}" />
        </sql:query>
        
        <c:url value="post.jsp" var="post">
            <c:param name="id" value="${param.id}" />
        </c:url>
        
        <c:if test="${userType!='G'}">
            <a href="<c:out value="${post}"/>">[Post New Message]</a>
        </c:if>
        <a href="main.jsp">[Exit]</a>
        
        <br />
        
        <table border="0" width="668">
            <tr>
                <td colspan="2" valign="top" bgcolor="#0000FF" width="662">
                    <p align="center">
                        <b>
                            <font color="#FFFFFF" size="4">&#160;
                                <c:out value="${name}" />
                            </font>
                        </b>
                    </p>
                </td>
            </tr>
            
            
            <c:forEach var="row" items="${messages.rows}"
                       varStatus="status">
                <c:choose>
                    <c:when test="${status.count%2==0}">
                        <c:set var="color" value="#eeeeff" />
                    </c:when>
                    
                    <c:otherwise>
                        <c:set var="color" value="#ddddff" />
                    </c:otherwise>
                </c:choose>
                
                <tr bgcolor="<c:out value="${color}"/>">
                    <td width="227" valign="top">
                        <table border="0" width="251">
                            <tr>
                                <td width="49">
                                    <b>From:</b>
                                </td>
                                
                                <td width="192">
                                    <c:out value="${row.c_sender}" />
                                </td>
                            </tr>
                            
                            <tr>
                                <td width="49">
                                    <b>Date:</b>
                                </td>
                                
                                <td width="192">
                                    <fmt:formatDate type="both"
                                                    value="${row.c_posted}" />
                                </td>
                            </tr>
                            
                            <tr>
                                <td width="49">
                                    <b>Subject:</b>
                                </td>
                                
                                <td width="192">
                                    <c:out value="${row.c_subject}" />
                                </td>
                            </tr>
                        </table>
                    </td>
                    
                    <td width="431">
                        <pre>
<c:out value="${row.c_message}" />


                        </pre>
                        
                        <c:if test="${userType=='A'}">
                            <c:url value="${pageContext.request.requestURI}"
                                   var="del">
                                <c:param name="mode" value="del" />
                                
                                <c:param name="forum" value="${param.id}" />
                                
                                <c:param name="msgnum" value="${row.c_number}" />
                            </c:url>
                            
                            <a href="${del}">[Delete]</a>
                        </c:if>
                    </td>
                </tr>
                
            </c:forEach>
        </table>
        <c:if test="${userType!='G'}">
            <a href="<c:out value="${post}"/>">[Post New Message]</a>
        </c:if>
        <a href="main.jsp">[Exit]</a>
    </body>
</html>

